<template>
    <div style="background-color: #ffffff;">
        <!-- :before-change="beforeChange" -->
        <!-- <HeadNav :title="'待供应'"></HeadNav> -->
        <!-- 周月年 -->
        <div class="content">
            <div class="contentTop">
                <div class="contentTop_wrapper">
                    <div class="wrapper_library">
                        <div class="library_sumNum">共计{{ dataList.supplierList.length }}项</div>
                        <div class="library_sumPrice">￥{{ amount }}</div>
                    </div>
                    <div class="supplierBox">
                        <div class="supplierItem" v-for="(item, index) in supplierList" :key="index">
                            <div class="supplierItem-label" v-if="item.specification">{{ item.materialName }}/{{
                                item.specification }}</div>
                            <div class="supplierItem-label" v-if="!item.specification">{{ item.materialName }}</div>
                            <div class="supplierItem-label">{{ item.num }}</div>
                        </div>
                        <div class="checked-more" v-if="dataList.supplierList.length > 3" @click="checkedMore">查看更多
                            <van-icon :name="showMore ? 'arrow-up' : 'arrow-down'" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="recordList" v-if="recordList.length > 0 && !loading">
                <div class="recordItem" v-for="(item, index) in recordList" :key="index"
                    @click="showDetail(item, index)">
                    <div class="recordItem_bg">
                        <div class="recordItemL">
                            <div class="recordItemL-left"><img :src="require('../../assets/images/recordIcon.png')"
                                    alt=""></div>
                            <div class="recordItemL-right">
                                <div class="recordItemL-right-text">{{ item.stallName }}</div>
                                <div class="recordItemL-right-text" style="margin-top: 8px;">{{ item.reportTime }}</div>
                            </div>
                        </div>
                        <div class="recordItemR">
                            <div class="recordItemR-left">
                                <div class="recordItemR-left-num">共{{ item.reportChildList.length }}项产品</div>
                                <div class="recordItemR-left-price" style="margin-top: 8px;">合￥{{ item.amount }}</div>
                            </div>
                            <div class="recordItemR-right" @click.stop="showDetail(item, index)">
                                <van-icon :name="item.isTag ? 'arrow-up': 'arrow-down'" size="11" />
                            </div>
                        </div>
                    </div>
                    <template v-if="item.reportChildList && item.reportChildList.length > 0">
                        <div class="details_box" v-if="item.isTag">
                            <div class="goods-box" v-for="(ele, val) in item.reportChildList" :key="val" :id="val">
                                <div class="goods-title">{{ ele.materialName }}({{
                                                ele.specification ? (' ' + ele.specification + '/ '):'()' }}{{ ele.unit
                                                ? (' ' + ele.unit + '/ ') : "" }} {{ ' ￥' + ele.price }})
                                </div>
                                <div class="goods-num">
                                    <div class="selectnum" @click="showInputNum(ele, val)">{{ ele.num }}</div>
                                </div>
                            </div>
                            <!-- <div class="recordBottom" v-if="currentItem == index && show">
                            <div class="recordBottom_item date">
                                <div class="recordBottom_item_label">入库时间</div>
                                <div class="recordBottom_item_text">2024.01.26 07:02:30 </div>
                            </div>
                            <div class="recordBottom_item mt19">
                                <div class="recordBottom_item_label">领取人</div>
                                <div class="recordBottom_item_name">
                                    <img class="" src="../../assets/images/name1.png" alt="">
                                </div>
                            </div>
                        </div> -->
                        </div>
                    </template>
                </div>
            </div>
            <!-- <div class="recordBottom">
                <div class="recordBottom_item mt19">
                    <div class="recordBottom_item_label">出库人</div>
                    <div class="recordBottom_item_name">
                        <img class="mr12" src="../../assets/images/name4.png" alt="">
                    </div>
                </div>
            </div> -->
            <div class="empty_content" v-if="recordList.length === 0 && !loading"> 当前暂无数据</div>
        </div>
        <foot></foot>
    </div>
</template>

<script>
/* eslint-disable */
import { getParams } from '@/common/public'
import HeadNav from '@/components/HeadNav'
import foot from '../foot/foot.vue'
import { supplierTodaySta, supplierTodayList } from '@/api/supplier'
import { Loading } from 'vant';

export default {
    name: 'SupplierLibrary',
    components: {
        HeadNav,
        foot
    },
    computed: {
        // ...mapState({
        //     token: (state) => state.applyrecords.token
        // })
    },
    watch: {
        active(newVal) {
            console.log('newVal', newVal)
            if (newVal === 0) {

            } else if (newVal === 0) {

            } else {

            }
        }
    },
    data() {
        return {
            amount: 0,
            loading: true,
            active: 0,
            dataList: {
                supplierList: []
            },
            recordList: [],
            show: true,
            current: 0,
            currentItem: -1,
            supplierList: [],
            showMore: false
        }
    },

    // beforeRouteEnter(to, from, next) {
    //     next((vm) => {
    //     vm.localData = JSON.parse(to.query.item)
    //     })
    // },
    mounted() {

        this._supplierTodaySta()
        this._supplierTodayList()
    },
    created() {

    },

    methods: {
        _supplierTodaySta() {
            supplierTodaySta().then(res => {
                console.log(res.data);
                this.amount = res.data.amount
                this.dataList.supplierList = res.data.detailList
                if (!this.showMore) {
                    this.supplierList = this.dataList.supplierList.slice(0, 3)
                } else {
                    this.supplierList = this.dataList.supplierList
                }
            })

        },
        _supplierTodayList() {
            this.loading = true
            supplierTodayList().then(res => {
                if (res.code == 200) {
                    this.recordList = res.data.records
                    console.log(this.recordList);
                    this.loading = false
                    this.recordList.forEach(ele => {
                        this.$set(ele,'isTag',false)
                    })
                }

            })
        },
        toCheck() { },
        // 展开申报明细
        showDetail(item, val) {
            console.log(item, val, 'xinxi ')
            this.currentItem = val
            this.show = !this.show
            item.isTag=!item.isTag
        },
        // changeSort(index, e, name) {
        //     this.current = index
        // },
        // 查看更多
        checkedMore() {
            this.showMore = !this.showMore
            if (!this.showMore) {
                this.supplierList = this.dataList.supplierList.slice(0, 3)
            } else {
                this.supplierList = this.dataList.supplierList
            }
        }
    },
    beforeDestroy() {
        console.log('index')
        window.removeEventListener('scroll', this.onLoad, true)
    }
}
</script>

<style lang="less" scoped>
span,
p {
    padding: 0;
    margin: 0;
}

/deep/.van-tab {
    z-index: 200;
    height: 44px;
    //  background:rgb(216, 143, 143);
}

/deep/.van-tabs__wrap .van-tabs__wrap--scrollable {
    position: fixed;
}

/deep/.van-tab--active {
    /* color: rgb(255, 152, 82); */
}

/deep/.van-tabs__line {
    height: 0.6vw;
    background-color: rgb(255, 152, 82);
}

.content {
    overflow: auto;
    margin-bottom: 10px;
    background: #ffffff;
    height: 100vh;
    padding-bottom: 50px;
}

.contentTop {
    // margin-top: 50px; //headNav使用时  不注释
    padding-top: 10px;
    background-color: #f9f9f9;

    .contentTop_wrapper {
        background-color: #ffffff;

        .wrapper_library {
            text-align: center;
            padding: 40px auto;
            border-bottom: 1px solid #e5e5e5;


            .library_sumNum {
                font-size: 15px;
                line-height: 15px;
                text-align: center;
                color: #000000;
                padding-top: 40px;
            }

            .library_sumPrice {
                font-size: 30px;
                line-height: 30px;
                text-align: center;
                color: #0081D3;
                margin-top: 14px;
                padding-bottom: 40px;
            }
        }

        .supplierBox {
            padding: 24px;

            .supplierItem {
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding-bottom: 30px;

                .supplierItem-label {
                    color: #000000;
                    font-size: 14px;
                    text-align: left;
                    line-height: 14px;
                }
            }

            .checked-more {
                text-align: center;
                color: #999999;
                font-size: 10px;
                line-height: 10px;
                display: flex;
                align-items: center;
                justify-content: center;
            }
        }
    }
}

.recordList {
    background: #f9f9f9;
    padding-bottom: 5px;
    // border-top: 2px solid #e5e5e5;
    // margin-top: 80px;
    padding-top: 10px;
    margin-bottom: 50px;
}

.recordItem {
    background-color: #ffffff;
    padding-bottom: 5px;
    margin-bottom: 5px;

    .recordItem_bg {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 24px;
    }

    .recordItemL {
        display: flex;
        align-items: center;
    }

    .recordItemL-left {
        width: 22px;
        height: 22px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;

        img {
            width: 22px;
            height: 22px;
        }

    }

    .recordItemL-right {
        display: flex;
        justify-content: center;
        flex-direction: column;
        margin-left: 12px;

        .recordItemL-right-text {
            font-size: 14px;
            color: #000000;
            text-align: left;
        }
    }

    .recordItemR {
        display: flex;
        align-items: center;

        .recordItemR-left {
            .recordItemR-left-num {
                color: #666666;
                font-size: 14px;
            }

            .recordItemR-left-price {
                color: #000000;
                font-size: 14px;
            }
        }


        .recordItemR-right {
            margin-left: 12px;
        }
    }
}

.recordItem:last-child {
    margin-bottom: 0px;
}

.details_box {
    padding: 0px 24px 12px 24px;
}

.goods-box {
    background-color: #ffffff;
    padding: 12px 24px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #e5e5e5;
    justify-content: space-between;

    .goods-title {
        font-size: 12px;
        line-height: 12px;
        text-align: left;
        color: #000000;
    }

    .goods-num {
        display: flex;
        align-items: center;

        .selectnum {
            font-size: 12px;
            text-align: center;
            color: #000000;
            margin: 0px 3px;
        }
    }

    .plus {
        width: 15px;
        height: 15px;
        background: #047DCB;
        border: none;
    }

    .minus {
        width: 15px;
        height: 15px;
        border: 1px solid #047DCB;
    }

    /deep/.van-button--normal {
        color: #ffffff !important;
        padding: 5px;
    }
}

// 无数据
.empty_content {
    height: 70vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    color: #000000;
    font-size: 16px;
    background: #ffffff;
}

.btnArea {
    padding: 24px;
    text-align: center;
}

/*清浮动*/
.clearfix:after {
    content: '';
    display: block;
    clear: both;
}

.clearfix {
    zoom: 1;
}



/deep/.van-tabs__wrap {
    touch-action: manipulation;
    border-top: none;
}

/deep/.van-tab {
    border-top: none;
    border-bottom: 1px solid rgba(245, 244, 249, 1);
}


.btnStockIn {
    border: 1px solid #047DCB;
    border-radius: 40px;
    color: #047DCB;
}

// 去逛逛
.loginBtn {
    width: 100%;
    height: 45px;
    border: none;
    background: #047DCB;
    border-radius: 45px;
}

.tips {
    margin-top: 25px;
    font-size: 14px;
    text-align: right;
    color: #000000;
    line-height: 14px;
}

.recordBottom {
    padding: 12px 24px;

    .recordBottom_item {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .recordBottom_item_label {
            font-size: 12px;
            line-height: 12px;
            text-align: left;
            color: #999999;
        }

        .recordBottom_item_text {
            font-size: 12px;
            line-height: 12px;
            text-align: left;
            color: #000000;
        }

        .recordBottom_item_name {
            display: flex;
            align-items: center;

            img {
                width: 54px;
                height: 30px;
            }
        }

    }
}

.btnArea {
    padding: 12px 24px;
    text-align: center;
}

.mr12 {
    margin-right: 12px;
}

.mt19 {
    margin-top: 19px;
}
</style>